<?php
/**
 * Created by PhpStorm.
 * User: yangwang
 * Date: 2024-04-26
 * Time: 14:40
 */

namespace App\Models\Cruise;


use App\Models\BaseModel;
use App\Models\Traits\KfSoftDeletes;
use App\Models\Traits\KfUid;
use Illuminate\Database\Eloquent\Relations\HasMany;

class CruiseShopLicenseRecordsModel extends BaseModel
{
    use KfUid;
    use KfSoftDeletes;

    protected $table = 'cruise_shop_license_records';

    protected $fillable = [
        'id',
        'shopId',
        'status',
        'merchantUpdatedAtByUid',
        'merchantUpdatedAt',
        'cruiseAt',
        'cruiseAtByUid',
        'createdAt',
        'createdByUid',
        'updatedAt',
        'updatedByUid',
        'isDeleted',
    ];

    const STATUS_LACK     = 0;
    const STATUS_PENDING  = 1;
    const STATUS_APPROVED = 2;
    const STATUS_REJECT   = 3;
    const STATUS_EXPIRED  = 4;

    const STATUS_MAP = [
        self::STATUS_LACK     => '证件缺失',
        self::STATUS_PENDING  => '待审核',
        self::STATUS_APPROVED => '审核通过',
        self::STATUS_REJECT   => '审核驳回',
        self::STATUS_EXPIRED  => '证件过期',
    ];

    const STATUS_WIGHT = [
        self::STATUS_LACK     => 0,
        self::STATUS_EXPIRED  => 1,
        self::STATUS_PENDING  => 2,
        self::STATUS_REJECT   => 3,
        self::STATUS_APPROVED => 4,
    ];

    public static function getStatus(int $businessLicenseStatus, int $foodLicenseStatus): int
    {
        if (empty($businessLicenseStatus) || empty($foodLicenseStatus)) {
            return self::STATUS_LACK;
        }

        if (self::STATUS_WIGHT[$businessLicenseStatus] <= self::STATUS_WIGHT[$foodLicenseStatus]) {
            return $businessLicenseStatus;
        } else {
            return $foodLicenseStatus;
        }
    }

    public function resourceRel(): HasMany
    {
        return $this->hasMany(CruiseShopLicenseResourceRecordsModel::class, 'shopId', 'shopId');
    }


}